//
//  WritePasteTableViewCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/5/4.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
@objc protocol OpenQrDelegate:class {
    func openQr()
    @objc optional func selectAddress()
}
class WritePasteTableViewCell: BaseTableViewCell {
    var sLine: UIView? = nil
    weak var delegate:OpenQrDelegate?
    lazy var textField: BaseTextField = {
        let textField = BaseTextField(changeView: nil, szBounds: CGRect.zero)
        textField.font = UIFont.systemFont(ofSize: 14)
        textField.placeholder = kText("输入或者长按粘贴地址")
        textField.setValue(UIFont.systemFont(ofSize: 14), forKeyPath: "_placeholderLabel.font")
        if ThemeManager.default.currentThemeMode() == .night {
            textField.setValue(UIColor(hexStr: "#616979"), forKeyPath: "_placeholderLabel.textColor")
        }else {
            textField.setValue(UIColor(hexStr: "#b1b2b2"), forKeyPath: "_placeholderLabel.textColor")
        }
        textField.themeTextColor  = ThemeManager.ThemeColorKeys.text1
        return textField
    }()
    
    lazy var titleLabel: UILabel = {
        let label = BaseLabel(style: .oneStyle)
        label.font = UIFont.systemFont(ofSize: 12)
        label.text = kText("至")
        return label
    }()
    
    lazy var qrBtn: UIButton = {
        let btn = UIButton()
        btn.themeSetImage(ThemeManager.ThemeImageKeys.qrCode, for: UIControlState.normal)
        return btn
    }()
    lazy var addressBtn:UIButton = {
        let btn = UIButton()
        btn.themeSetImage(ThemeManager.ThemeImageKeys.assetAddress, for: UIControlState.normal)
        return btn
    }()
    
    lazy var allBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle(kText("全部"), for: UIControlState.normal)
        btn.themeSetTitleColor(ThemeManager.ThemeColorKeys.text1, for: UIControlState.normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        return btn
    }()
    
    lazy var zlLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor(hexStr: "#757b86")
        return label
    }()
   
    override func setUpUI() {
        super.setUpUI()
        self.contentView.addSubview(textField)
        textField.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-105)
            make.height.equalTo(38)
        }
        
        let sLine = UIView()
        self.sLine = sLine
        sLine.themeBackground = ThemeManager.ThemeColorKeys.tabLineColor
        self.contentView.addSubview(sLine)
        sLine.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-48)
            make.bottom.equalToSuperview().offset(-14)
            make.height.equalTo(14)
            make.width.equalTo(0.5)
        }
        
        self.contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(5)
        }
        
        self.contentView.addSubview(qrBtn)
        qrBtn.addTarget(self, action: #selector(openQr), for: UIControlEvents.touchUpInside)
        qrBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(0)
            make.centerY.equalTo(sLine)
            make.width.equalTo(48)
            make.height.equalTo(20)
        }
        
        self.addSubview(addressBtn)
        addressBtn.addTarget(self, action: #selector(selectAddress), for: UIControlEvents.touchUpInside)
        addressBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-49)
            make.centerY.equalTo(sLine)
            make.width.equalTo(48)
            make.height.equalTo(20)
        }
    }
    
    override func setModel(model: BaseModel) {
        
    }
    
    @objc func selectAddress() {
        if delegate != nil && delegate?.selectAddress != nil {
            self.delegate?.selectAddress!()
        }
    }
    
    @objc func openQr() {
        if delegate != nil {
            self.delegate?.openQr()
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
